import { TypeKeys } from "@/focus/type";
import { switchStore } from "../../store";
export const TypeProps = {
  onEnter: {
    type: Function,
  },
  onBack: {
    type: Function,
  },
  onHome: {
    type: Function,
  },
  onBackspace: {
    type: Function,
  },
  onDel: {
    type: Function,
  },
  onMenu: {
    type: Function,
  },
  onFocus: {
    type: Function,
  },
  onUnfocus: {
    type: Function,
  },
  onKeydown: {
    type: Function,
  },
  widgetId: {
    type: String,
    default: ""
  },
  scrollNo: {
    type: Number,
  },
  onMoveFocus: {
    type: Function,
    default: () => () => { }
  },
  goleft: {
    type: Array<string>,
    default: () => []
  },
  goright: {
    type: Array<string>,
    default: () => []
  },
  goup: {
    type: Array<string>,
    default: () => []
  },
  godown: {
    type: Array<string>,
    default: () => []
  },
  //顺序跳转，左右移动到侧边时按照顺序跳转
  sequence: {
    type: Boolean,
    default: () => false
  },
}

export const TypeEmits = ["enter", "back", "home", "backspace", "del", "menu", "focus", "unfocus", "keydown"]

export function onkeydown(emit: Function, key: keyof TypeKeys, keyCode: number,) {
  const _keyboard = switchStore.keys
  if (keyCode === _keyboard.ENTER) {
    emit("enter")
    return
  }
  if (keyCode === _keyboard.BACK) {
    emit("back")
    return
  }
  if (keyCode === _keyboard.HOME) {
    emit("home")
    return
  }
  if (keyCode === _keyboard.BACKSPACE) {
    emit("backspace")
    return
  }
  if (keyCode === _keyboard.DEL) {
    emit("del")
    return
  }
  if (keyCode === _keyboard.MENU) {
    emit("menu")
    return
  }
  if (!key) return
  emit("keydown", key, keyCode)
}